package com.example.myapplication;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class MyThread extends Thread{
    Handler handler;
    public MyThread(Handler handler) {
        this.handler = handler;
    }

    @Override
    public void run() {
        try {
            URL url = new URL("https://img2.baidu.com/it/u=728391417,58732684&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500");
            HttpURLConnection coon = (HttpURLConnection) url.openConnection();
            InputStream input = coon.getInputStream();
            if (coon.getResponseCode() == 200){
                Bitmap bitmap = BitmapFactory.decodeStream(input);
                Message mes = new Message();
                mes.obj = bitmap;
                handler.sendMessage(mes);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
